﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Security.Principal;

namespace BCDVHD
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            if (!VerifyWindows7())
            {
                MessageBox.Show("The windows version  must be at least 7!");
                return;
            }
            if (!VerifyAdministrator())
            {
                MessageBox.Show("Please run as administrator!");
                return;
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmVHD());
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            MessageBox.Show(string.Format("Sorry, error :{0}{1}Please write at ignatandrei@yahoo.com about this error", e.ExceptionObject.ToString(),Environment.NewLine));

        }

        private static bool VerifyAdministrator()
        {
            return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
        }

        private static bool VerifyWindows7()
        {
            var osinfo = Environment.OSVersion;
            if (!(osinfo.Platform == PlatformID.Win32NT))
                return false;
            if (osinfo.Version.Major < 6)
                return false;
            if (osinfo.Version.Minor == 0)
                return false;

            return true;
        }
    }
}
